package bandi.osgi.dalservice.service.devices.impl;

import java.util.List;

import bandi.osgi.dal.dao.beans.Device;
import bandi.osgi.dal.dao.beans.DeviceType;
import bandi.osgi.dal.dao.beans.User;
import bandi.osgi.dal.dao.devices.DeviceDAO;
import bandi.osgi.dal.dao.devicetypes.DeviceTypeDAO;
import bandi.osgi.dal.dao.users.UsersDAO;
import bandi.osgi.dalservice.service.devices.DeviceService;

public class DeviceServiceImpl implements DeviceService {
	
	private DeviceDAO dd;
	private DeviceTypeDAO dtd;
	private UsersDAO ud;
	
	

	public DeviceServiceImpl(DeviceDAO dd, DeviceTypeDAO dtd, UsersDAO ud) {
		super();
		this.dd = dd;
		this.dtd = dtd;
		this.ud = ud;
	}

	@Override
	public void deleteDevice(Device device) {
		dd.deleteDevice(device);
	}

	@Override
	public List<Device> getAllDevices() {
		List<Device> list = dd.getAllDevices();
		for(Device d : list){
			d.setDevice_type(dtd.getDeviceType(d.getDevice_type().getDevice_type_id()));
			d.setUser(ud.getUser(d.getUser().getUser_id()));
		}
		return list;
	}

	@Override
	public Device getDevice(long deviceID) {
		Device d = dd.getDevice(deviceID);
		//create full objects from the dummy objects
		d.setDevice_type(dtd.getDeviceType(d.getDevice_type().getDevice_type_id()));
		d.setUser(ud.getUser(d.getUser().getUser_id()));
		return d;
	}

	@Override
	public List<Device> getDevices(User user) {
		List<Device> list = dd.getDevices(user);
		for(Device d : list){
			d.setDevice_type(dtd.getDeviceType(d.getDevice_type().getDevice_type_id()));
			d.setUser(ud.getUser(d.getUser().getUser_id()));
		}
		return list;
	}

	@Override
	public List<Device> getDevices(DeviceType deviceType) {
		List<Device> list = dd.getDevices(deviceType);
		for(Device d : list){
			d.setDevice_type(dtd.getDeviceType(d.getDevice_type().getDevice_type_id()));
			d.setUser(ud.getUser(d.getUser().getUser_id()));
		}
		return list;
	}

	@Override
	public void insertDevice(Device device) {
		dd.insertDevice(device);
	}

	@Override
	public void updateDevice(Device device) {
		dd.updateDevice(device);
	}

}
